<template>
	<view class="pl10 pr10 d-flex a-center flex-wrap">
		<view class="mb15 width-33 pl5 pr5 boxSizing" v-for="(item,index) in ggqyData" :key="index">
			<view class="w100p">
				<view class="content_item p10 boxSizing">
					<view class="itemName d-flex a-center">
						<view class="point mr5"></view>
						<view class="fs14">{{item}}</view>
					</view>
					<view class="height28p mt15 mb10 itemBoxPadding bdr4" :class="classroomDataBgColor[ggqyDataStatus[index]]">
						<view class="w100p h100p d-flex a-center j-sb">
							<view class="d-flex-center mr5">
								<u--image src="/static/img/feature/children/icon_V.png" width="40rpx"
									height="40rpx"></u--image>
							</view>
							<view class="d-flex a-center fs14">
								<view class="mr5 white">{{ggqyDataCount1[index]}}
								</view>
								<view class="unit fs12">V</view>
							</view>
						</view>
					</view>
					<view class="height28p itemBoxPadding bdr4" :class="classroomDataBgColor[ggqyDataStatus[index]]">
						<view class="w100p h100p d-flex a-center j-sb">
							<view class="d-flex-center mr5">
								<u--image src="/static/img/feature/children/icon_A.png" width="40rpx"
									height="40rpx"></u--image>
							</view>
							<view class="d-flex a-center fs14">
								<view class="mr5 white">{{ggqyDataCount2[index]}}
								</view>
								<view class="unit fs12">A</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		queryOneListWorkingByAppNum,
		queryOneListWorkingByAppStatus
	} from "@/api/dormBuilding/oneBuildFourFloor.js"

	export default {
		data() {
			return {
				timeout: [],

				ggqyData: ['东过道1', '东过道2', '西过道', '应急灯', '饮水机', '洗衣机'],

				ggqyDataCount1: [],
				ggqyDataCount2: [],
				ggqyDataStatus: [],

				classroomDataBgColor: ['bgColor_info', 'bgColor_success', 'bgColor_danger', 'bgColor_blue',
					'bgColor_warning', 'bgColor_red', 'bgColor_orange'
				],
				classroomDataBorder: ['border_info', 'border_success', 'border_danger', 'border_blue',
					'border_warning', 'border_red', 'border_orange'
				],
				classroomDataFontColor: ['font_info', 'font_success', 'font_danger', 'font_blue',
					'font_warning', 'font_red', 'font_orange'
				],
			}
		},
		mounted() {
			this.queryOneListWorkingByAppNum()
			this.queryOneListWorkingByAppStatus()

			this.setupTimer()
		},
		methods: {
			// 设置定时器
			setupTimer() {
				let _this = this;
				_this.timeout[0] = setInterval(() => {
					_this.queryOneListWorkingByAppNum()
				}, 15000);
				_this.timeout[1] = setInterval(() => {
					_this.queryOneListWorkingByAppStatus()
				}, 30000);
			},
			// 清除定时器
			clearTimer() {
				let _this = this;
				if (_this.timeout.length > 0) {
					_this.timeout.forEach(item => {
						clearInterval(item);
					})
				}
			},
			async queryOneListWorkingByAppNum() {
				await queryOneListWorkingByAppNum().then(res => {
					let tempData = res.object || []

					let arrData1 = []
					let arrData2 = []
					for (var i = 0; i < tempData.length; i++) {
						arrData1.push(tempData[i].deviceList[0].deviceValue)
						arrData2.push(tempData[i].deviceList[1].deviceValue)
					}
					this.ggqyDataCount1 = arrData1
					this.ggqyDataCount2 = arrData2
					
					let yjd = arrData2[3]
					let ysj = arrData2[4]
					
					let yjd2 = this.$subtractAndAssign(yjd, ysj)
					this.$set(this.ggqyDataCount2, 3, yjd2);
				})
			},
			async queryOneListWorkingByAppStatus() {
				await queryOneListWorkingByAppStatus().then(res => {
					let tempData = res.object || []

					let arrData = []
					for (var i = 0; i < tempData.length; i++) {
						arrData.push(tempData[i].socketColor)
					}
					this.ggqyDataStatus = arrData
				})
			},
		}
	}
</script>
<style lang="scss" scoped>
	@import url("@/static/css/operationData.css");
</style>